// index.js
// 1.引入腾讯地图的的js文件
const QQMapWX = require("../../libs/qqmap-wx-jssdk.min.js")
// 导入request
import {getHomData} from "../../api/home"
// 获取应用实例
const app = getApp()

Page({
  data: {
    address: "",
    homeData: null
  },
  getCurrentAddress() {
    // 1. 获取经纬度坐标
    wx.getLocation({
      altitude: 'altitude',
      success: (res)=> {
        console.log(res)
        // 2. 将经纬度坐标 -> 地址
        let qqmapsdk = new QQMapWX({
          key: 'VJVBZ-KMSCV-DKMPG-UTRSH-QIKWV-IRBVZ'
        });

        qqmapsdk.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          success: (res)=> {
            console.log(res)
            this.setData({
              address: res.result.address
            })
          }
        })
      }
    })
    
  },
  async onLoad() {
    this.getCurrentAddress();
    const data = await getHomData()
    console.log(data)
    this.setData({
      homeData: data.data
    })
  },
  onShow() {

  },
  onReady() {
    
  }
})
